<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改积分红包规则</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/cba/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/cba/my.css/}" media="all">
</head>
<body class="childrenBody">
<form class="layui-form html_save" lay-filter="form">

    <div class="layui-form-item">
        <label class="layui-form-label">积分等级</label>
        <div class="layui-input-block">
            <select name="dictDataId" id="dictDataId">
                <option th:each="entry : ${levelMap}" th:value="${entry.value}" th:text="${entry.key}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">总金额（元）</label>
        <div class="layui-input-block">
            <input class="layui-input" name="totalMoney" placeholder="请输入总金额" type="text" lay-verify="number">
            <input class="layui-input" name="id" id="id" type="hidden">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">最小领取（元）</label>
        <div class="layui-input-block">
            <input class="layui-input" name="minMoney" placeholder="如：0.01" type="text" lay-verify="number">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">最大领取（元）</label>
        <div class="layui-input-block">
            <input class="layui-input" name="maxMoney" placeholder="推荐为平均值的2倍" type="text" lay-verify="number">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数量</label>
        <div class="layui-input-block">
            <input class="layui-input" name="num" placeholder="分成多少份" type="text" lay-verify="number">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">强制删除所有用户数据，按新规则重新分配红包</label>
        <div class="layui-input-block">
            <input type="checkbox" name="forceValid" lay-skin="switch" lay-text="强制|不强制" id="forceValid">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveContainer">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/cba/login-timeout.js}"></script>
<!--<script type="text/javascript" src="js/newsadd.js"></script>-->

<script type="text/javascript" th:inline="javascript">
    layui.use(['table', 'form', "layer"], function () {

        // 操作对象
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;

        var rule = [[${packetIntegralRule}]];
        if (rule != null) {
            form.val("form", {
                "totalMoney": rule.totalMoney // "name": "value"
                , "num": rule.num
                , "maxMoney": rule.maxMoney
                , "minMoney": rule.minMoney
                , "status": rule.status
                , "id": rule.id
            });

            $("#dictDataId").val(rule.dictDataId);
            form.render("select", null); //刷新select选择框渲染
        }


        //监听提交
        form.on('submit(saveContainer)', function (data) {
            data.field.forceValid = data.field.forceValid == "on" ? 1 : 0;

            $.ajax({
                url: [[${basePath}]] + "/packet/integral/rule/save",
                data: data.field,
                sync: "post",
                success: function (data) {
                    if (data.success) {
                        layer.msg(data.msg, {icon: 1});
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.href = [[${basePath}]] + "/packet/integral/rule/index";
                            parent.layer.close(index);
                        }, 1500);
                    } else {
                        layer.msg(data.msg, {icon: 5});
                    }
                }
            });

            return false;
        });

    });
</script>
</body>
</html>